# import random
import unittest
import time

from HTMLTestRunner import HTMLTestRunner
from selenium import webdriver
class loginA(unittest.TestCase):
    def setUp(self):
        self.op=webdriver.Firefox()
        self.op.get("http://192.168.2.125/agileone")
        # self.str=random.randint(2000,9000)
    def test_login(self):
        # self.op.find_element_by_id("username").clear()
        self.op.find_element_by_id("username").send_keys("admin123")
        # self.op.find_element_by_id("password").clear()
        self.op.find_element_by_id("password").send_keys("admin")
        self.op.find_element_by_id("login").click()
        time.sleep(5)
        s=self.op.find_element_by_id("msg").text
        self.assertIn("出错啦",s)
        self.op.close()

    def test_login1(self):
        self.op.find_element_by_id("username").send_keys("admin")
        self.op.find_element_by_id("password").send_keys("admin123")
        self.op.find_element_by_id("login").click()
        time.sleep(5)
        s = self.op.find_element_by_id("msg").text
        self.assertIn("出错啦", s)
        self.op.close()
    def test_login2(self):
        self.op.find_element_by_id("username").send_keys("")
        self.op.find_element_by_id("password").send_keys("admin")
        self.op.find_element_by_id("login").click()
        time.sleep(5)
        s = self.op.find_element_by_id("msg").text
        self.assertIn("出错啦", s)
        self.op.close()
    def test_login3(self):
        self.op.find_element_by_id("username").send_keys("admin")
        self.op.find_element_by_id("password").send_keys("")
        self.op.find_element_by_id("login").click()
        time.sleep(5)
        s = self.op.find_element_by_id("msg").text
        self.assertIn("出错啦", s)
        self.op.close()
    def test_login4(self):
        self.op.find_element_by_id("username").send_keys("admin")
        self.op.find_element_by_id("password").send_keys("admin")
        self.op.find_element_by_id("login").click()
        time.sleep(5)
        s=self.op.find_element_by_partial_link_text("注销").text
        self.assertEqual(s,"注销")
        self.op.close()
    def tearDown(self):
        print("ok")

if __name__ == '__main__':
    # t=loginA()
    # t.test_setup()
    # t.test_login('admin','admin123')
    # t.test_login('admin123', 'admin')
    # t.test_login('admin', '')
    # t.test_login('', '')
    # t.test_login('admin', 'admin')
    # t.test_link()
    # t.test_add("dsfdfefwe")
    # t.test_add("343")
    # t.test_quary("343")
    # t.test_quary("8798098")
    # t.test_edit("jljljii")
    # t.test_delete()
    # t.test_tearDown()
    suite = unittest.TestSuite()
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(loginA))
    #
    # with open("test-report1.html", 'w', encoding="utf-8") as f:
    #     runner = unittest.TextTestRunner(stream=f, verbosity=2, descriptions="test report")
    #     runner.run(suite)

    with open("test-report1.html", 'w', encoding="utf-8") as f:
        runner = HTMLTestRunner(stream=f,verbosity=1,title="测试报告",description="unitetest 简单测试报告")
        runner.run(suite)


